package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.MerchantEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.CollectibleListContract
import com.dgshanger.sanhxiaofeisc.mvp.model.CollectibleListModel
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter
import com.xx.baseutilslibrary.network.rx.RxHttpObserver

/**
 * Created by JacobHHH on 2018/5/11.
 */
class CollectibleListPresenter : BaseRxMvpPresenter<CollectibleListContract.Model,CollectibleListContract.View>(),CollectibleListContract.Presenter {

    override fun loadData(isRefresh: Boolean, page: String?) {
        getModel().loadData(page,object :RxHttpObserver<List<MerchantEntity>>(){
            override fun onCompleted(msg: String?, entity: List<MerchantEntity>?) {
                if (isRefresh){
                    getView()?.setData(entity)
                }else{
                    getView()?.addData(entity)
                }
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
                getView()?.showError(Throwable(error),isRefresh)
                getView()?.onDataFailure(error)
            }

            override fun onLoadingStart() {
                attachObserver(this)
            }

            override fun onLoadingFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun createModel(): CollectibleListContract.Model = CollectibleListModel()
}